package br.com.officium.managedbean.cadastro;

import br.com.officium.util.BeanUtil;
import java.io.Serializable;
import javax.faces.component.UIComponent;
import javax.faces.component.UIPanel;

/**
 *
 * @author Ivo
 */
public abstract class CadastroAbstractBean implements Serializable {

    public static final int ROW_NUMBER = 10;
    public static final String INDEX = "/index.jsf?faces-redirect=true";
    
    public static final String LISTAR_STATE = "listagem";
    public static final String EDITAR_STATE = "edicao";
    public static final String CADASTRAR_STATE = "cadastro";
    
    private String currentState = LISTAR_STATE;
    
    public UIPanel panelForm;

    public boolean isCadastro() {
        return CADASTRAR_STATE.equals(currentState);
    }

    public boolean isListagem() {
        return LISTAR_STATE.equals(currentState);
    }

    public boolean isEdicao() {
        return EDITAR_STATE.equals(currentState);
    }

    public String getCurrentState() {
        return currentState;
    }

    public void setCurrentState(String currentState) {
        this.currentState = currentState;
    }

    public abstract String listar();

    public abstract void cadastrar();

    public abstract void editar();

    public abstract void excluir();

    public void prepararEditar() {
        setCurrentState(EDITAR_STATE);
    }

    public String cancelar() {
        return INDEX;
    }

    public boolean isPaginator() {
        return true;
    }

    public Integer getRowNumber() {
        return ROW_NUMBER;
    }

    public void cleanSubmittedValues(UIComponent component) {
        BeanUtil.cleanSubmittedValues(component);
    }
}
